﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using Users;
using Lists;
using Sim;


namespace Lists
{
    [Serializable()]
    public class JudgeList
    {
        public List<Judge> judgeList { get; set; }

        public JudgeList()
        {
            judgeList = new List<Judge>();
        }

        public int AddJudge(Judge j)
        {
            for (int i = 0; i < judgeList.Count(); i++)
            {
                if (j.username == judgeList[i].username)
                {
                    return 0;
                }
            }
            for (int i = 0; i < UserList.userList.Count(); i++)
            {
                if (j.username == UserList.userList[i].username && j.level == 1 && UserList.userList[i].level == 1)
                {
                    j.id = UserList.userList[i].id;
                    judgeList.Add(j);
                    break;
                }
            }
            return 1;
        }

        public int AddJudge(string username)
        {
            for (int i = 0; i < judgeList.Count(); i++)
            {
                if (username == judgeList[i].username)
                {
                    return 0;
                }
            }
            for (int i = 0; i < UserList.userList.Count(); i++)
            {
                if (username == UserList.userList[i].username && UserList.userList[i].level == 1)
                {
                    Judge j = new Judge();
                    j.id = UserList.userList[i].id;
                    j.firstName = UserList.userList[i].firstName;
                    j.lastName = UserList.userList[i].lastName;
                    j.age = UserList.userList[i].age;
                    j.nation = UserList.userList[i].nation;
                    j.sex = UserList.userList[i].sex;
                    j.username = UserList.userList[i].username;
                    judgeList.Add(j);
                    break;
                }
            }
            return 1;
        }

        public void RemoveJudge(int index)
        {
            judgeList.RemoveAt(index);
        }
    }
}
